<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/datapicker/datepicker3.css}" rel="stylesheet"/>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-user-add">
			<input name="deptId"  type="hidden" id="treeId"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">部门名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" readonly="true" id="treeName">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">活动标题：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="title" id="title">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">活动地点：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="place" id="place" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">举办时间：</label>
				<div class="col-sm-9">
					<div class="form-group">
						<div class="input-group date"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>

							<input type="text" class="form-control" name="operateTime" id="operateTime" value="2019-04-20">
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">结束时间：</label>
				<div class="col-sm-9">
					<div class="form-group">
						<div class="input-group date"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>

							<input type="text" class="form-control" name="endTime" id="endTime" value="2019-05-20">
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">主持人：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="manager" id="manager">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">举办单位：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="hostDeptment" id="hostDeptment">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">学分：</label>
				<div class="col-sm-8">
					<input class="form-control" type="number" name="score" id="score">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">经费：</label>
				<div class="col-sm-8">
					<input class="form-control" type="number" name="money" id="money">
				</div>
			</div>

			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script th:src="@{/ajax/libs//datapicker/bootstrap-datepicker.js}"></script>
	<script>
        $("#form-user-add").validate({
        	rules:{
                title:{
        			required:true,
        			minlength: 2,
        			maxlength: 20,
        		},
                place:{
        			required:true,
        		},
        		manager:{
        			required:true,
        		},
                hostDeptment:{
        			required:true,
        		},
        	},
        	submitHandler:function(form){
        		add();
        	}
        });

        function add() {
        	var title = $("input[name='title']").val();
        	var deptId = $("input[name='deptId']").val();
        	var place = $("input[name='place']").val();
        	var operateTime = $("input[name='operateTime']").val();
        	var manager = $("input[name='manager']").val();
        	var hostDeptment = $("input[name='hostDeptment']").val();
        	var score = $("input[name='score']").val();
        	var money = $("input[name='money']").val();
        	var endTime = $("input[name='endTime']").val();
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : "/system/activity/add",
        		data : {
        			"title": title,
        			"deptId": deptId,
        			"place": place,
        			"operateTime": operateTime,
        			"manager": manager,
        			"hostDeptment": hostDeptment,
        			"score": score,
        			"money": money,
					"endTime":endTime
        		},
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }

        /*用户管理-新增-选择部门树*/
        function selectDeptTree() {
        	var treeId = $("#treeId").val();
        	var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        	var url = ctx + "system/dept/selectDeptTree/" + deptId;
			var options = {
				title: '选择部门',
				width: "380",
				height: "380",
				url: ctx + "system/dept/selectDeptTree/" + deptId,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
				var body = layer.getChildFrame('body', index);
    			$("#treeId").val(body.find('#treeId').val());
    			$("#treeName").val(body.find('#treeName').val());
    			layer.close(index);
			}
		}

        $(".input-group.date").datepicker(
            {
                format : 'yyyy-mm-dd',
				todayBtn: "linked",
				keyboardNavigation: !1,
				forceParse: !1,
				calendarWeeks: !0,
				autoclose: !0
            });
    </script>
</body>
</html>
